package gyb.rasa.controller;


import com.baomidou.mybatisplus.extension.api.R;
import gyb.rasa.common.utils.Result;
import gyb.rasa.entity.MessageReceived;
import gyb.rasa.entity.Video;
import gyb.rasa.entity.vo.EntityQuestions;
import gyb.rasa.entity.vo.HotQuestion;
import gyb.rasa.service.HotService;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 郜宇博
 * @since 2023-04-20
 */
@RestController
@RequestMapping("/api")
public class HotController {
    private final HotService hotService;

    public HotController(HotService hotService) {
        this.hotService = hotService;
    }

    @ApiOperation("增加entity的热度")
    @GetMapping("addHot")
    public Result getVideosByDisease(@RequestParam("entity") String entity) {
        hotService.increaseHot(entity);
        return Result.ok();
    }
    @ApiOperation("获取热门回答")
    @GetMapping("hotQuestions")
    public Result getHotQuestions(@RequestParam("countEntity") Integer countEntity,
                                  @RequestParam("countQuestion") Integer countQuestion){
        List<HotQuestion> hotQuestions = hotService.getHotQuestions(countEntity,countQuestion);
        if (hotQuestions != null){
            return Result.ok().data("hotQuestions",hotQuestions);
        }else {
            return Result.error().message("获取热门问答失败");
        }
    }
    @ApiOperation("根据实体名获取热门问答")
    @GetMapping("hotQuestionsWithEntity")
    public Result getHotQuestionByEntity(@RequestParam("entitys") String entitys,
                                         @RequestParam("countQuestion") Integer countQuestion){

        Map<String,List<HotQuestion>>  hotQuestionsWithEntity = hotService.getHotQuestionsByEntity(entitys,countQuestion);
        if (hotQuestionsWithEntity != null){
            return Result.ok().data("hotQuestions",hotQuestionsWithEntity);
        }else {
            return Result.error().message("获取实体、热门问答失败");
        }
    }
    @ApiOperation("根据实体名获取热门问答")
    @GetMapping("hotQuestionsWithSingleEntity")
    public Result getHotQuestionBySingleEntity(@RequestParam("entity") String entity,
                                         @RequestParam("countQuestion") Integer countQuestion){

        EntityQuestions entityQuestions = hotService.getHotQuestionsBySingleEntity(entity,countQuestion);
        if (entityQuestions != null){
            return Result.ok().data("entityQuestions",entityQuestions);
        }else {
            return Result.error().message("获取实体、热门问答失败");
        }
    }

}

